--------------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  C:/yourdirectory/logs/coalprod.log
  log type:  text
 opened on:  18 Jun 2016, 19:02:14

. 
. set more off

. set matsize 1000

. 
. 
. *_______________________________________________________________________________
. 
. 
. /* Get monthly production and consumption data (thousand short tons) */
.    
. use "`dir_input'/eia_coalprodcons.dta", clear

. 
. tsset Counter
        time variable:  Counter, 1 to 488
                delta:  1 unit

. 
. gen delta_prod = Production-L.Production
(17 missing values generated)

. gen pct_prod = ln(Production/L.Production)
(17 missing values generated)

. 
. gen eventmonth = 0

. replace eventmonth = 1 if (Year==2010 & Month==4)
(1 real change made)

. 
. * Production regressions
. xi: ivreg2 pct_prod eventmonth, kernel(bartlett) bw(auto) small 

OLS estimation
--------------

Estimates efficient for homoskedasticity only
Statistics robust to autocorrelation
  kernel=Bartlett; bandwidth=    29
  Automatic bw selection according to Newey-West (1994)
  time variable (t):  Counter

                                                      Number of obs =      487
                                                      F(  1,   485) =     0.33
                                                      Prob > F      =   0.5633
Total (centered) SS     =  6.041728346                Centered R2   =   0.0007
Total (uncentered) SS   =  6.042447931                Uncentered R2 =   0.0008
Residual SS             =  6.037556443                Root MSE      =    .1116

------------------------------------------------------------------------------
    pct_prod |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
  eventmonth |  -.0646567   .1117958    -0.58   0.563    -.2843206    .1550072
       _cons |   .0013483   .0013048     1.03   0.302    -.0012154     .003912
------------------------------------------------------------------------------
Included instruments: eventmonth
------------------------------------------------------------------------------

. estimates store nofe

. xi: ivreg2 pct_prod eventmonth i.Month, kernel(bartlett) bw(auto) small 
i.Month           _IMonth_1-12        (naturally coded; _IMonth_1 omitted)

OLS estimation
--------------

Estimates efficient for homoskedasticity only
Statistics robust to autocorrelation
  kernel=Bartlett; bandwidth=    29
  Automatic bw selection according to Newey-West (1994)
  time variable (t):  Counter

                                                      Number of obs =      487
                                                      F( 12,   474) =    12.73
                                                      Prob > F      =   0.0000
Total (centered) SS     =  6.041728346                Centered R2   =   0.2887
Total (uncentered) SS   =  6.042447931                Uncentered R2 =   0.2888
Residual SS             =  4.297415771                Root MSE      =   .09522

------------------------------------------------------------------------------
    pct_prod |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
  eventmonth |   .0079629   .0960491     0.08   0.934    -.1807718    .1966975
   _IMonth_2 |  -.0594016    .024662    -2.41   0.016    -.1078619   -.0109412
   _IMonth_3 |   .0904321   .0270038     3.35   0.001     .0373701    .1434941
   _IMonth_4 |  -.0897786    .025215    -3.56   0.000    -.1393256   -.0402316
   _IMonth_5 |  -.0010202   .0261821    -0.04   0.969    -.0524674    .0504271
   _IMonth_6 |  -.0142289   .0233522    -0.61   0.543    -.0601155    .0316577
   _IMonth_7 |  -.0746843   .0213018    -3.51   0.000    -.1165419   -.0328266
   _IMonth_8 |   .0944309   .0233861     4.04   0.000     .0484776    .1403843
   _IMonth_9 |  -.0459847   .0263133    -1.75   0.081    -.0976899    .0057205
  _IMonth_10 |   .0222086   .0252414     0.88   0.379    -.0273904    .0718075
  _IMonth_11 |  -.0846743    .027173    -3.12   0.002    -.1380688   -.0312798
  _IMonth_12 |  -.0466696   .0247935    -1.88   0.060    -.0953883    .0020492
       _cons |   .0185074   .0170621     1.08   0.279    -.0150193     .052034
------------------------------------------------------------------------------
Included instruments: eventmonth _IMonth_2 _IMonth_3 _IMonth_4 _IMonth_5
                      _IMonth_6 _IMonth_7 _IMonth_8 _IMonth_9 _IMonth_10
                      _IMonth_11 _IMonth_12
------------------------------------------------------------------------------

. estimates store monthfe

. xi: ivreg2 pct_prod eventmonth i.Month i.Year, kernel(bartlett) bw(auto) small  
i.Month           _IMonth_1-12        (naturally coded; _IMonth_1 omitted)
i.Year            _IYear_1973-2013    (naturally coded; _IYear_1973 omitted)

OLS estimation
--------------

Estimates efficient for homoskedasticity only
Statistics robust to autocorrelation
  kernel=Bartlett; bandwidth=    29
  Automatic bw selection according to Newey-West (1994)
  time variable (t):  Counter

                                                      Number of obs =      487
                                                      F( 52,   434) =     3.38
                                                      Prob > F      =   0.0000
Total (centered) SS     =  6.041728346                Centered R2   =   0.3047
Total (uncentered) SS   =  6.042447931                Uncentered R2 =   0.3048
Residual SS             =  4.200977543                Root MSE      =   .09839

------------------------------------------------------------------------------
    pct_prod |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
  eventmonth |   .0030818    .107472     0.03   0.977    -.2081485    .2143121
   _IMonth_2 |  -.0593809   .0257104    -2.31   0.021    -.1099133   -.0088486
   _IMonth_3 |   .0904527   .0281687     3.21   0.001     .0350887    .1458168
   _IMonth_4 |  -.0896389   .0262862    -3.41   0.001     -.141303   -.0379748
   _IMonth_5 |  -.0009996   .0272294    -0.04   0.971    -.0545174    .0525183
   _IMonth_6 |  -.0142083   .0242438    -0.59   0.558     -.061858    .0334415
   _IMonth_7 |  -.0746636   .0221192    -3.38   0.001    -.1181377   -.0311896
   _IMonth_8 |   .0944516   .0242836     3.89   0.000     .0467234    .1421797
   _IMonth_9 |  -.0458906   .0273897    -1.68   0.095    -.0997235    .0079424
  _IMonth_10 |   .0223027   .0263145     0.85   0.397    -.0294169    .0740224
  _IMonth_11 |  -.0845802   .0283594    -2.98   0.003    -.1403191   -.0288413
  _IMonth_12 |  -.0465754   .0258525    -1.80   0.072    -.0973871    .0042362
 _IYear_1974 |   -.015892   .0212561    -0.75   0.455    -.0576697    .0258857
 _IYear_1975 |   .0253467   .0195114     1.30   0.195     -.013002    .0636954
 _IYear_1976 |   .0047484   .0187235     0.25   0.800    -.0320516    .0415485
 _IYear_1977 |  -.0523085   .0187177    -2.79   0.005    -.0890972   -.0155198
 _IYear_1978 |   .0547987   .0187177     2.93   0.004       .01801    .0915874
 _IYear_1979 |  -.0006833   .0187177    -0.04   0.971     -.037472    .0361053
 _IYear_1980 |   .0140097   .0187177     0.75   0.455     -.022779    .0507983
 _IYear_1981 |   .0044967   .0187177     0.24   0.810     -.032292    .0412853
 _IYear_1982 |  -.0161148   .0187177    -0.86   0.390    -.0529034    .0206739
 _IYear_1983 |   .0004907   .0187177     0.03   0.979     -.036298    .0372794
 _IYear_1984 |  -.0001346   .0187177    -0.01   0.994    -.0369233     .036654
 _IYear_1985 |   .0074283   .0187177     0.40   0.692    -.0293604     .044217
 _IYear_1986 |   .0039022   .0187177     0.21   0.835    -.0328865    .0406909
 _IYear_1987 |   .0062328   .0187177     0.33   0.739    -.0305559    .0430215
 _IYear_1988 |   .0008103   .0187177     0.04   0.965    -.0359784     .037599
 _IYear_1989 |  -.0069626   .0187177    -0.37   0.710    -.0437513     .029826
 _IYear_1990 |   .0011799   .0187177     0.06   0.950    -.0356088    .0379686
 _IYear_1991 |   .0041435   .0187177     0.22   0.825    -.0326452    .0409322
 _IYear_1992 |    .003131   .0187177     0.17   0.867    -.0336577    .0399196
 _IYear_1993 |  -.0032526   .0187177    -0.17   0.862    -.0400412    .0335361
 _IYear_1994 |   .0077193   .0187177     0.41   0.680    -.0290694     .044508
 _IYear_1995 |  -.0071023   .0187177    -0.38   0.705     -.043891    .0296863
 _IYear_1996 |   .0053187   .0187177     0.28   0.776      -.03147    .0421074
 _IYear_1997 |     .00742   .0187177     0.40   0.692    -.0293687    .0442087
 _IYear_1998 |   -.000789   .0187177    -0.04   0.966    -.0375776    .0359997
 _IYear_1999 |  -.0019353   .0187177    -0.10   0.918    -.0387239    .0348534
 _IYear_2000 |  -.0086593   .0187177    -0.46   0.644     -.045448    .0281293
 _IYear_2001 |   .0040326   .0187177     0.22   0.830     -.032756    .0408213
 _IYear_2002 |   .0023098   .0187177     0.12   0.902    -.0344789    .0390985
 _IYear_2003 |   .0006226   .0187177     0.03   0.973    -.0361661    .0374112
 _IYear_2004 |   .0027888   .0187177     0.15   0.882    -.0339999    .0395774
 _IYear_2005 |  -.0026589   .0187177    -0.14   0.887    -.0394476    .0341298
 _IYear_2006 |   .0025213   .0187177     0.13   0.893    -.0342674    .0393099
 _IYear_2007 |  -.0028439   .0187177    -0.15   0.879    -.0396326    .0339448
 _IYear_2008 |   .0054544   .0187176     0.29   0.771    -.0313341    .0422429
 _IYear_2009 |  -.0124118   .0187178    -0.66   0.508    -.0492007    .0243771
 _IYear_2010 |   .0055871   .0208946     0.27   0.789    -.0354801    .0466543
 _IYear_2011 |   .0009012    .018717     0.05   0.962    -.0358859    .0376884
 _IYear_2012 |  -.0135827   .0187073    -0.73   0.468     -.050351    .0231855
 _IYear_2013 |   .0037655   .0236677     0.16   0.874     -.042752    .0502831
       _cons |   .0176617   .0220157     0.80   0.423    -.0256089    .0609322
------------------------------------------------------------------------------
Included instruments: eventmonth _IMonth_2 _IMonth_3 _IMonth_4 _IMonth_5
                      _IMonth_6 _IMonth_7 _IMonth_8 _IMonth_9 _IMonth_10
                      _IMonth_11 _IMonth_12 _IYear_1974 _IYear_1975 _IYear_1976
                      _IYear_1977 _IYear_1978 _IYear_1979 _IYear_1980
                      _IYear_1981 _IYear_1982 _IYear_1983 _IYear_1984
                      _IYear_1985 _IYear_1986 _IYear_1987 _IYear_1988
                      _IYear_1989 _IYear_1990 _IYear_1991 _IYear_1992
                      _IYear_1993 _IYear_1994 _IYear_1995 _IYear_1996
                      _IYear_1997 _IYear_1998 _IYear_1999 _IYear_2000
                      _IYear_2001 _IYear_2002 _IYear_2003 _IYear_2004
                      _IYear_2005 _IYear_2006 _IYear_2007 _IYear_2008
                      _IYear_2009 _IYear_2010 _IYear_2011 _IYear_2012
                      _IYear_2013
------------------------------------------------------------------------------

. estimates store yearfe

. 
. 
. local specif_list "nofe monthfe yearfe"

. 
. foreach specif of local specif_list{
  2.         /* obtain residuals so can do SQ test and normality tests */
.         estimates restore `specif'
  3.         predict resid_`specif', residual
  4.         *egen std_resid_`specif'  = std(resid_`specif')
. 
.         * save residuals for taking into Excel
.         save "`dir_output'/temp_results.dta", replace
  5.         drop if eventmonth==1
  6.         keep resid_*
  7.         *xpose, clear varname
.         save "`dir_output'/resids.dta", replace
  8.         use "`dir_output'/temp_results.dta"  /* get all variables back */       
  9.         
.         drop if eventmonth==1
 10.         * Shapiro-Wilk test for normality
.         swilk resid_`specif'
 11.         * Jarque-Bera test for normality
.         jb6 resid_`specif'
 12.         use "`dir_output'/temp_results.dta", clear  /* get all variables back */        
 13. }
(results nofe are active now)
(17 missing values generated)
(note: file C:/yourdirectory/output/coal_prod/temp_results.dta not found)
file C:/yourdirectory/output/coal_prod/temp_results.dta saved
(1 observation deleted)
(note: file C:/yourdirectory/output/coal_prod/resids.dta not found)
file C:/yourdirectory/output/coal_prod/resids.dta saved
(1 observation deleted)

                   Shapiro-Wilk W test for normal data

    Variable |    Obs       W           V         z       Prob>z
-------------+--------------------------------------------------
  resid_nofe |    486    0.86989     42.664     9.011    0.00000
Jarque-Bera normality test:   3057 Chi(2)      0
Jarque-Bera test for Ho: normality: (resid_nofe)
(results monthfe are active now)
(17 missing values generated)
file C:/yourdirectory/output/coal_prod/temp_results.dta saved
(1 observation deleted)
file C:/yourdirectory/output/coal_prod/resids.dta saved
(1 observation deleted)

                   Shapiro-Wilk W test for normal data

    Variable |    Obs       W           V         z       Prob>z
-------------+--------------------------------------------------
resid_mont~e |    486    0.80191     64.954    10.020    0.00000
Jarque-Bera normality test:   7518 Chi(2)      0
Jarque-Bera test for Ho: normality: (resid_monthfe)
(results yearfe are active now)
(17 missing values generated)
file C:/yourdirectory/output/coal_prod/temp_results.dta saved
(1 observation deleted)
file C:/yourdirectory/output/coal_prod/resids.dta saved
(1 observation deleted)

                   Shapiro-Wilk W test for normal data

    Variable |    Obs       W           V         z       Prob>z
-------------+--------------------------------------------------
resid_yearfe |    486    0.81783     59.733     9.819    0.00000
Jarque-Bera normality test:   6005 Chi(2)      0
Jarque-Bera test for Ho: normality: (resid_yearfe)

. 
. drop if eventmonth==1
(1 observation deleted)

. 
. 
. /* Plot density of residuals and original variable*/
. kdensity resid_yearfe, generate(x_resid_base y_resid_base) nograph                      

. keep x_* y_*

. save "`dir_output'/kdensity_base.dta", replace
(note: file C:/yourdirectory/output/coal_prod/kdensity_base.dta not found)
file C:/yourdirectory/output/coal_prod/kdensity_base.dta saved

. use "`dir_output'/temp_results.dta"  /* get all variables back */       

. drop if eventmonth==1
(1 observation deleted)

. kdensity pct_prod, generate(x_var y_var) nograph                        

. keep x_* y_*

. save "`dir_output'/kdensity_originalvar.dta", replace
(note: file C:/yourdirectory/output/coal_prod/kdensity_originalvar.dta not found)
file C:/yourdirectory/output/coal_prod/kdensity_originalvar.dta saved

. use "`dir_output'/temp_results.dta"  /* get all variables back */       

. 
. log close
      name:  <unnamed>
       log:  C:/yourdirectory/logs/coalprod.log
  log type:  text
 closed on:  18 Jun 2016, 19:02:17
--------------------------------------------------------------------------------------------------------------------------
